alphadex-sdk-js
TypeScript icon, indicating that this package has built-in type declarations

0.12.15 • Public • Published

alphadex-sdk-js (AlphaDEX Javascript SDK)

alphadex-sdk-js is a typescript/javascript package to help developers integrate effortlessly with the AlphaDEX decentralised exchange on Radix DLT

It provides developers with easy access to the live data on the AlphaDEX exchange as well as a number of convenience functions and classes/types for working with the exchange.

Interesting note: alphadex-sdk-js connects to the AlphaDEX Websocket server to provide the live data feed without any intervention needed from the developer.

Installation

Node.js and NPM

You will need node.js and npm (node package manager) installed on your machine in order to add alphadex-sdk-js to your project. If you do not yet have it installed, you can find instructions to do so here

Add alphadex-sdk-js to your project

To add alphadex-sdk-js to your project, run the following command from the root directory of your project:

npm install --save alphadex-sdk-js

Updating the SDK

Update to latest patch (non-breaking changes)

To update the SDK for any new changes that are non-breaking (either bug fixes or feature additions), you can run the following command in your project directory:

npm update alphadex-sdk-js

Update to latest version (including breaking changes)

To update the SDK to the very latest version (which might include breaking changes), you can run the following command in your project directory:

npm install --save alphadex-sdk-js@latest

Usage

Import required variables and functions

To use alphadex-sdk-js in your project, you need to import at least the init function and the clientState object. You will need to import and run the init function in the first file that executes (e.g. index.js).

For ease of use it is suggested to import all the alphadex-sdk-js functions and variables as one combined reference (e.g. adex, but you can choose any name). This has the benefit that it clearly distinguishes the AlphaDEX SDK functions from your app's own native functions and will provide auto-complete functionality in your editor to help you choose the appropraite function.

Example: Import all AlphaDEX SDK functions and variables as one reference called adex.

import * as adex from "alphadex-sdk-js";

Alternatively you can import each function and variable individually.

Example: Import functions and variables individually.

import { init, clientState } from "alphadex-sdk-js";

Initialize the AlphaDEX SDK

In order to connect the AlphaDEX SDK to the live data on the AlphaDEX exchange you need to run the init function in the root file of your project (e.g. index.js). This function will connect to the AlphaDEX websocket server and ensure that the sdk variables are kept in sync with the live data on the exchange.

Example: Run the init function to initialize the sdk connection with the AlphaDEX exchange (using combined import as adex).

// import all the sdk functions and variables as adex
import * as adex from "alphadex-sdk-js";
...
// run the sdk init function to establish a live connection with the exchange
adex.init();

// use the variables with the live data in your program/app
let adexState = adex.clientState;
console.log("Status of the alphadex sdk connection: "+adexState.status);

Example: Run the init function to initialize the sdk connection with the AlphaDEX exchange (using individual imports).

// import init function and clientState variable individually
import { clientState, init } from "alphadex-sdk-js";
...
// run the sdk init function to establish a live connection with the exchange
init();

// use the variables with the live data in your program/app
let adexState = clientState;
console.log("Status of the alphadex sdk connection: "+adexState.status);

Using variables in alphadex-sdk-js

alphadex-sdk-js gives the developer access to a number of variables that are constantly updated to reflect the latest state of the AlphaDEX exchange.

All variables have a static and observable version (indicated by a $ at the end of the variable name).

Example: static and observable version of a variable

let staticStatus = adex.clientState.status;
let observableStatus = adex.clientState.status$;

All these variables are provided in one object called clientState.

clientState object

The clientState object holds all variables that reflect the live state of the AlphaDEX exchange. This object must be initialized by calling the init function.

Example: Calling the init function to initialize the clientState object and assigning the clientState object to a local variable myAdexState.

import * as adex from "alphadex-sdk-js";

// call the init function to connect to the AlphaDEX exchange
// and initialize the clientState object
adex.init();

// assign the clientState object to a local variable
let myAdexState = adex.clientState;

Variables

All the variables below are accessed as fields of the clientState object.

Example: How to access a variable.

// Accessing the status variable
let connectionStatus = adex.clientState.status

Read + Write Variables

These variables can be changed by the user. When the variables are changed they will automatically cause all related variables to update automatically.

Variable Type Description Access
alphadexApiServerUrl($) string The URL of the Api/Websocket server that the SDK is connected to. Read + Write
currentCandlePeriod($) string The currently selected candle period. Candle data is used for candlestick charts. This variable can be changed by the user, but must be one of the valid values specified in CandlePeriods. Read + Write
currentPairAddress($) string The on-ledger component address of the currently selected AlphaDEX pair. alphadex-sdk-js will provide live updated details of various variables associated with the currently selected pair. The user can change this variable to another pair address and all the variables associated with the current pair will automatically update for the new pair. Read + Write
getAllPairsMarketData($) boolean Flag that indicates whether the market data for all pairs on AlphaDEX should be kept updated. Be aware that when this flag is true it could use a lot of bandwith. It is suggested to only set it to true when required. Read + Write
stateChangeFrequency number The number of milliseconds between state change emits from the stateChanged$ observable variable. Setting this value to 0, will effectively mean that all state changes are emitted individually. The default for this variable is 500 i.e. the stateChanged$ observable will emit the latest state every half second. Read + Write

Read Only Variables

Variable Type Description Access
stateChanged$ Observable <StaticState> Observable that gets emitted every time one of the AlphaDEX variables change. This observable is useful for applications that need to manually update their state variables. It emits a StaticState object that contains read-only versions of the AlphaDEX variables (similar to the clientState object, but no variables can be changed). Read Only
alphadexAddress($) string The on-ledger component address of the AlphaDEX exchange component. Read Only
adminBadgeAddress($) string The on-ledger resource address of the AlphaDEX Admin badge. AlphaDEX Admin badges are used to identify accounts that have admin permissions on the AlphaDEX exchange. Read Only
maxPlatformFee($) number The maximum fee that platforms/apps can specify as their platform fee (expressed in decimals). E.g. alphadexMaxPlatformFee = 0.001 (0.1%) Read Only
currentPairCandlesList($) Array of Candle A sorted list of the candle (open, close, high, low) history for the currently selected AlphaDEX pair using the candle period specified by the currentCandlePeriod variable. Read Only
currentPairInfo($) PairInfo Basic information about the currently selected AlphaDEX pair. This variable will automatically update when currentPairAddress is changed. Read Only
currentPairOrderbook($) Orderbook Orderbook information about the currently selected AlphaDEX pair. This variable will automatically update when currentPairAddress is changed. Read Only
currentPairTrades($) Array of Trade List of most recent trades for the currently selected AlphaDEX pair. The number of trades in the list is determined by the value of the maxTrades variable. This variable will automatically update when currentPairAddress is changed. Read Only
epochsPerPeriod($) number The number of epochs between AlphaDEX pairs checking to see if they need to update their liquidity fee. Read Only
allowRecallableTokens($) boolean Indicates whether recallable tokens are allowed in new pairs on the exchange Read Only
allowFreezableTokens($) boolean Indicates whether freezable tokens are allowed in new pairs on the exchange Read Only
exchangeFee($) number The portion of the fee due to the AlphaDEX exchange on every trade (expressed in decimals). E.g. alphadexExchangeFee = 0.0005 (0.05%) Read Only
newPairFee($) number The cost in XRD to create a new pair on AlphaDEX. Read Only
pairsList($) Array of PairInfo An array/list of all the pairs listed on the AlphaDEX exchange. The list is not sorted in any particular order. Read Only
pairsMap($) Map<string, PairInfo> A map of all the pairs listed on the AlphaDEX exchange, indexed by the pair's on-ledger component address. Read Only
platformBadgeAddress($) string The on-ledger resource address of the AlphaDEX Platform badge. AlphaDEX Platform badges are issued to platforms/apps that will submit orders to the AlphaDEX exchange. Each badge holds information about the platform and the platform fee for submitting orders. Read Only
priceMaxDecimals($) number The maximum number of decimal digits allowed in any AlphaDEX price. Read Only
priceSignificantDigits($) number The number of significant digits to allow in an AlphaDEX price. Read Only
status($) ClientStatus Shows the status of the connection with the AlphaDEX exchange. Can be one of 3 values: "LOADING", "READY", "OFFLINE" Read Only
tokensList($) Array of TokenInfo An array/list of all the tokens listed on the AlphaDEX exchange. The list is not sorted in any particular order. Read Only
tokensMap($) Map<string, TokenInfo> A map of all the tokens listed on the AlphaDEX exchange, indexed by the token's on-ledger resource address. Read Only
xrdAddress($) string The on-ledger resource address of the XRD (Radix) token. This address is used to uniquely identify the XRD token. Read Only

Functions List

Setup Functions

Functions to initialize and destroy the SDK connection to the AlphaDEX exchange.

Function Name Description
init Connects SDK to AlphaDEX exchange and initializes the clientState object.
destroy Stops SDK connection with AlphaDEX exchange and resets clientState object.

Create Transaction Functions

Functions that create a transaction manifest that can be submitted to a user wallet for signing.

Function Name Description
createCancelOrderTx Create a transaction manifest for cancelling an exchange order.
createExchangeOrderTx Create a transaction manifest for an exchange order.
createNewPlatformBadgeTx Create a transaction manifest to create a new platform badge.
createChangePlatformFeeTx Create a transaction manifest to change the fee of a platform badge.
createChangePlatformNameTx Create a transaction manifest to change the name of a platform badge.
createNewPairTx Create a transaction manifest to create a new pair.
createSwapTx Create a transaction manifest for a swap.

Submit Transaction Functions

Functions that submit a transaction directly to the user wallet for signing.

Function Name Description
submitCancelOrder Transaction to cancel an exchange order.
submitExchangeOrder Transaction to create a new exchange order.
submitNewPlatformBadgeTx Transaction to create a new platform badge.
submitChangePlatformFeeTx Transaction to change the fee of a new platform badge.
submitChangePlatformNameTx Transaction to change the name of a new platform badge.
submitNewPairTx Transaction to create a new pair
submitSwap Transaction to submit a new swap
submitTransaction Utility function to submit any transaction manifest to the user wallet

Get Data Functions

Functions that fetch AlphaDEX related data from a specific account or set of accounts or the ledger.

Function Name Description
getAccountOrders Gets all order receipts in the specified account
getPairOrders Gets specified order receipts for the specified pair
getPlatformBadges Gets all platform badges in the specified accounts
getPlatformBadgeInfo Gets platform badge info for a specified platform id

Get Quotes Functions

Functions that provide an estimated quote of tokens received and exchange costs for a planned order/swap. Useful to show a user the estimated outcome of an order/swap.

Function Name Description
getExchangeOrderQuote Estimated quote for an exchange order
getSwapQuote Estimated quote for a swap

Functions Details

init() [async function] (back to Functions List)

Function that connects the SDK to the AlphaDEX exchange websocket server and initializes the clientState object.

Parameters:

Parameter Description Type Example
alphadexApiNetwork (optional) The type of AlphaDEX api/websocket server the SDK must connect to. If not specified it will use "mainnet". ApiNetwork "mainnet"
alphadexApiVersion (optional) The version of the alphadex API to use. If not specified it will use "v0". "v0" is the only current API version available. string "v0"

Returns: Promise of SDKResult

Successful SDKResult data field : nothing


Function that disconnects the SDK from the AlphaDEX exchange websocket server and clears the clientState object.

It is suggested to call this function when a live connection to the AlphaDEX exchange is no longer needed or when the user exits your app.

Parameters: None

Returns: Nothing


getExchangeOrderQuote() [async function] (back to Functions List)

Function that returns an estimated quote for a new AlphaDEX exchange order.

Parameters:

Parameter Description Type Example
pairAddress The on-ledger component address of the AlphaDEX pair for this order. string "component_7t45r624hjfguyfr"
orderType The type of order. Valid values = "LIMIT", "POST-ONLY", "MARKET". OrderType or string OrderType.LIMIT or "LIMIT"
side The side for the order. Valid values = "BUY", "SELL". OrderSide or string OrderSide.BUY or "BUY"
tokenAddress The on-ledger resource address of the specified token for the order. string "resource_634gafe55ey8674j"
amount The amount of the token to process in the order number 12.54
platformId The platform id for the order. Specified in decimals number 0.001
price (ignored if set to -1) The price limit to apply for the order. Either price or slippage must be specified. number 4.657
slippage (ignored if set to -1) The amount of price slippage that can be tolerated for the order, specified in decimals. Either price or slippage must be specified. number 0.05

Returns: Promise of SDKResult

Successful SDKResult data field : Quote (Estimated outcome of the specified exchange transaction)


createExchangeOrderTx() [async function] (back to Functions List)

Function to create a transaction manifest for creating a new AlphaDEX exchange order.

Parameters:

Parameter Description Type Example
pairAddress The on-ledger component address of the AlphaDEX pair for this order. string "component_7t45r624hjfguyfr"
orderType The type of order. Valid values = "LIMIT", "POST-ONLY", "MARKET". OrderType or string OrderType.LIMIT or "LIMIT"
side The side for the order. Valid values = "BUY", "SELL". OrderSide or string OrderSide.BUY or "BUY"
tokenAddress The on-ledger resource address of the specified token for the order. string "resource_634gafe55ey8674j"
amount The amount of the token to process in the order number 12.54
price (ignored if orderType = "MARKET", set to -1) The price at which to submit the order. number 4.657
slippage (ignored if orderType <> "MARKET", set to -1) The amount of price slippage that can be tolerated for the order, specified in decimals. number -1
platformBadgeId The platform badge id that should be used to determine the platform fee for the order. number 564
submitAccountAddress The on-ledger address of the account that will sign this transaction string account_763gd872dg23
settleAccountAddress The on-ledger address of the account that the order will settle to. If "", unmatched order tokens will need to be claimed later using the order receipt. string account_763gd872dg23

Returns: Promise of SDKResult

Successful SDKResult data field : string (The transaction manifest to be submitted by the user)


submitExchangeOrder() [async function] (back to Functions List)

Function to submit a new AlphaDEX exchange order.

It will create the required transaction manifest and submit to the user's wallet for signing. After the transaction the user should see a new order receipt in their wallet with the details of the order as well as any changes in tokens as a result of the order.

Parameters:

Parameter Description Type Example
pairAddress The on-ledger component address of the AlphaDEX pair for this order. string "component_7t45r624hjfguyfr"
orderType The type of order. Valid values = "LIMIT", "POST-ONLY", "MARKET". OrderType or string OrderType.LIMIT or "LIMIT"
side The side for the order. Valid values = "BUY", "SELL". OrderSide or string OrderSide.BUY or "BUY"
tokenAddress The on-ledger resource address of the specified token for the order. string "resource_634gafe55ey8674j"
amount The amount of the token to process in the order number 12.54
price (ignored if orderType = "MARKET", set to -1) The price at which to submit the order. number 4.657
slippage (ignored if orderType <> "MARKET", set to -1) The amount of price slippage that can be tolerated for the order, specified in decimals. number -1
platformBadgeId The platform badge id that should be used to determine the platform fee for the order. number 564
submitAccountAddress The on-ledger address of the account that will sign this transaction string account_763gd872dg23
settleAccountAddress The on-ledger address of the account that the order will settle to. If "", unmatched order tokens will need to be claimed later using the order receipt. string "" or account_763gd872dg23
rdt A reference to the Radix Dapp Toolkit that has been initialised in your app. See the appropriate documentation to use the Radix Wallet in your app here.

Returns: Promise of SDKResult

Successful SDKResult data field : object (The transaction detail object returned by the Radix Gateway API)


createCancelOrderTx() [async function] (back to Functions List)

Function to create a transaction manifest for cancelling an AlphaDEX exchange order.

Parameters:

Parameter Description Type Example
pairAddress The on-ledger component address of the AlphaDEX pair that the order belongs to. string component_u6erf78egfq4fqd
orderId The id of the order to cancel. number 5
accountAddress The on-ledger address of the account that will sign this transaction string account_763gd872dg23

Returns: Promise of SDKResult

Successful SDKResult data field : string (The transaction manifest to be submitted by the user)


submitCancelOrder() [async function] (back to Functions List)

Function to cancel an AlphaDEX exchange order.

It will create the required transaction manifest and submit to the user's wallet for signing. After the transaction the user might see any unallocated tokens returned to their wallet and the order receipt should have a status of "CANCELLED".

Parameters:

Parameter Description Type Example
pairAddress The on-ledger component address of the pair that the order to be cancelled belongs to. string resource_u6erf78egfq4fqd
orderId The id fo the order to be cancelled. number 5
accountAddress The on-ledger address of the account that will sign this transaction string account_763gd872dg23
rdt A reference to the Radix Dapp Toolkit that has been initialised in your app. See the appropriate documentation to use the Radix Wallet in your app here.

Returns: Promise of SDKResult

Successful SDKResult data field : object (The transaction detail object returned by the Radix Gateway API)


getSwapQuote() [async function] (back to Functions List)

Function that returns an estimated quote for a new AlphaDEX swap.

Parameters:

Parameter Description Type Example
fromTokenAddress The on-ledger resource address of the token to swap from. string resource_u6erf78egfq4fqd
fromTokenAmount The amount of the token to swap number 5.43
toTokenAddress The on-ledger resource address of the token to swap to. string resource_jgefw6dgw4fjw3s
maxSlippage The maximum price slippage to allow in the swap specified in decimals number 0.05
platformId The platform id that should be used to determine the platform fee for the swap. number 12

Returns: Promise of SDKResult

Successful SDKResult data field : string (The transaction manifest to be submitted by the user)

createSwapTx() [async function] (back to Functions List)

Function to create a transaction manifest for creating a new AlphaDEX swap order.

Parameters:

Parameter Description Type Example
fromTokenAddress The on-ledger resource address of the token to swap from. string resource_u6erf78egfq4fqd
fromTokenAmount The amount of the token to swap number 5.43
toTokenAddress The on-ledger resource address of the token to swap to. string resource_jgefw6dgw4fjw3s
maxSlippage The maximum price slippage to allow in the swap specified in decimals number 5.43
platformId The platform id that should be used to determine the platform fee for the swap. number 12
accountAddress The on-ledger address of the account that will sign this transaction string account_763gd872dg23

Returns: Promise of SDKResult

Successful SDKResult data field : string (The transaction manifest to be submitted by the user)


submitSwap() [async function] (back to Functions List)

Function to submit a new AlphaDEX swap order.

It will create the required transaction manifest and submit to the user's wallet for signing. After the transaction the user should see a new order receipt in their wallet with the details of the order as well as any changes in tokens as a result of the order.

Parameters:

Parameter Description Type Example
fromTokenAddress The on-ledger resource address of the token to swap from. string resource_u6erf78egfq4fqd
fromTokenAmount The amount of the token to swap number 5.43
toTokenAddress The on-ledger resource address of the token to swap to. string resource_jgefw6dgw4fjw3s
maxSlippage The maximum price slippage to allow in the swap specified in decimals number 5.43
platformId The platform id that should be used to determine the platform fee for the swap. number 12
accountAddress The on-ledger address of the account that will sign this transaction string account_763gd872dg23
rdt A reference to the Radix Dapp Toolkit that has been initialised in your app. See the appropriate documentation to use the Radix Wallet in your app here.

Returns: Promise of SDKResult

Successful SDKResult data field : object (The transaction detail object returned by the Radix Gateway API)


createNewPairTx() [async function] (back to Functions List)

Function to create a transaction manifest for creating a new AlphaDEX Pair.

Parameters:

Parameter Description Type Example
token1Address The on-ledger resource address of the first token in the pair string resource_u6erf78egfq4fqd
token1Address The on-ledger resource address of the second token in the pair string resource_u6erf78egfq4fqd
estimatedPrice The estimated price of the pair in decimals. The price should be specified as the number of token2 you can get for 1 token1. number 9.57
platformBadgeId The platform badge id of the platform through which this transaction is submitted number 12
accountAddress The on-ledger address of the account that will sign this transaction string account_763gd872dg23

Returns: Promise of SDKResult

Successful SDKResult data field : string (The transaction manifest to be submitted by the user)


submitNewPairTx() [async function] (back to Functions List)

Function for creating a new AlphaDEX pair. It will create the required transaction manifest and submit to the user's wallet for signing. Note that there is a cost of 500XRD to create a new pair.

Parameters:

Parameter Description Type Example
token1Address The on-ledger resource address of the first token in the pair string resource_u6erf78egfq4fqd
token1Address The on-ledger resource address of the second token in the pair string resource_u6erf78egfq4fqd
estimatedPrice The estimated price of the pair in decimals. The price should be specified as the number of token2 you can get for 1 token1. number 9.57
platformBadgeId The platform badge id of the platform through which this transaction is submitted number 12
accountAddress The on-ledger address of the account that will sign this transaction string account_763gd872dg23
rdt A reference to the Radix Dapp Toolkit that has been initialised in your app. See the appropriate documentation to use the Radix Wallet in your app here.

Returns: Promise of SDKResult

Successful SDKResult data field : object (The transaction detail object returned by the Radix Gateway API)


createNewPlatformBadgeTx() [async function] (back to Functions List)

Function to create a transaction manifest for creating a new AlphaDEX Platform Badge.

Parameters:

Parameter Description Type Example
name The name of the platform/app that will own the badge. Note that it is possible for a single platform to have multiple badges with different fees. It is therefore suggested that this name is consistent across platform badges for the same platform. string "My Cool App"
fee The fee that is associated with this badge expressed in decimals. This value cannot be higher than the value specified in the alphadexMaxPlatformFee variable. number 0.001
accountAddress The on-ledger address of the account that will sign this transaction string account_763gd872dg23

Returns: Promise of SDKResult

Successful SDKResult data field : string (The transaction manifest to be submitted by the user)


submitNewPlatformBadgeTx() [async function] (back to Functions List)

Function for creating a new AlphaDEX Platform Badge. It will create the required transaction manifest and submit to the user's wallet for signing. After the transaction the user should see the new platform badge in their wallet.

Parameters:

Parameter Description Type Example
name The name of the platform/app that will own the badge. Note that it is possible for a single platform to have multiple badges with different fees. It is therefore suggested that this name is consistent across platform badges for the same platform. string "My Cool App"
fee The fee that is associated with this badge expressed in decimals. This value cannot be higher than the value specified in the alphadexMaxPlatformFee variable. number 0.001
accountAddress The on-ledger address of the account that will sign this transaction string account_763gd872dg23
rdt A reference to the Radix Dapp Toolkit that has been initialised in your app. See the appropriate documentation to use the Radix Wallet in your app here.

Returns: Promise of SDKResult

Successful SDKResult data field : object (The transaction detail object returned by the Radix Gateway API)


createChangePlatformFeeTx() [async function] (back to Functions List)

Function to create a transaction manifest for changing the fee on an AlphaDEX Platform Badge.

Parameters:

Parameter Description Type Example
platformId The id of the platform badge for which to change the fee number 3
newFee The new fee for the specified badge expressed in decimals. This value cannot be higher than the value specified in the alphadexMaxPlatformFee variable. number 0.001
accountAddress The on-ledger address of the account that holds the specified platform badge and that will sign this transaction string account_763gd872dg23

Returns: Promise of SDKResult

Successful SDKResult data field : string (The transaction manifest to be submitted by the user)


submitChangePlatformFeeTx() [async function] (back to Functions List)

Function for changing the fee on an AlphaDEX Platform Badge. It will create the required transaction manifest and submit to the user's wallet for signing. After the transaction the user should see the new fee reflected in the data of the platform badge.

Parameters:

Parameter Description Type Example
platformId The id of the platform badge for which to change the fee. number 3
newFee The new fee for the specified badge expressed in decimals. This value cannot be higher than the value specified in the alphadexMaxPlatformFee variable. number 0.001
accountAddress The on-ledger address of the account that holds the specified platform badge and that will sign this transaction string account_763gd872dg23
rdt A reference to the Radix Dapp Toolkit that has been initialised in your app. See the appropriate documentation to use the Radix Wallet in your app here.

Returns: Promise of SDKResult

Successful SDKResult data field : object (The transaction detail object returned by the Radix Gateway API)


createChangePlatformNameTx() [async function] (back to Functions List)

Function to create a transaction manifest for changing the platform name on an AlphaDEX Platform Badge.

Parameters:

Parameter Description Type Example
platformId The id of the platform badge for which to change the platform name number 3
newName The new platform name for the specified badge. string "New Platform"
accountAddress The on-ledger address of the account that holds the specified platform badge and that will sign this transaction string account_763gd872dg23

Returns: Promise of SDKResult

Successful SDKResult data field : string (The transaction manifest to be submitted by the user)


submitChangePlatformNameTx() [async function] (back to Functions List)

Function for changing the platform name on an AlphaDEX Platform Badge. It will create the required transaction manifest and submit to the user's wallet for signing. After the transaction the user should see the new platform name reflected in the data of the platform badge.

Parameters:

Parameter Description Type Example
platformId The id of the platform badge for which to change the fee. number 3
newName The new platform name for the specified badge. string "New Platform"
accountAddress The on-ledger address of the account that holds the specified platform badge and that will sign this transaction string account_763gd872dg23
rdt A reference to the Radix Dapp Toolkit that has been initialised in your app. See the appropriate documentation to use the Radix Wallet in your app here.

Returns: Promise of SDKResult

Successful SDKResult data field : object (The transaction detail object returned by the Radix Gateway API)


getAccountOrders() [async function] (back to Functions List)

Function to fetch AlphaDEX orders for a specifc pair from an account.

Parameters:

Parameter Description Type Example
accountAddress The on-ledger address of the account to scan for order receipts string account_763gd872dg23
pairAddress The on-ledger component address of the pair to find orders for. string resource_u6erf78egfq4fqd
from The order id to start start searching from. This is used when results are paginated. number 346

Returns: Promise of SDKResult

Successful SDKResult data field : Array of OrderReceipt


getPairOrders() [async function] (back to Functions List)

Function to fetch the specified AlphaDEX orders for a specifc pair.

Parameters:

Parameter Description Type Example
pairAddress The on-ledger component address of the pair to find orders for. string resource_u6erf78egfq4fqd
orderIds The list of order ids to get. number [1,4,56, 657]

Returns: Promise of SDKResult

Successful SDKResult data field : Array of OrderReceipt


getPlatformBadges() [async function] (back to Functions List)

Function to fetch AlphaDEX platform badges for a list of accounts.

Parameters:

Parameter Description Type Example
accountAddresses The on-ledger address of the accounts to scan for platform badges. Array of string ["account_763gd872dg23"]

Returns: Promise of SDKResult

Successful SDKResult data field : Array of PlatformBadge


getPlatformBadgeInfo() [async function] (back to Functions List)

Function to fetch AlphaDEX platform badge information for a specified platform id.

Parameters:

Parameter Description Type Example
platformId The platform id for which to get information. number 2

Returns: Promise of SDKResult

Successful SDKResult data field : Array of PlatformBadge


submitTransaction() [async function] (back to Functions List)

Function for submitting a transaction manifest to the user's wallet for signing.

Parameters:

Parameter Description Type Example
manifest The transaction manifest for the transaction string
rdt A reference to the Radix Dapp Toolkit that has been initialised in your app. See the appropriate documentation to use the Radix Wallet in your app here.

Returns: Promise of SDKResult

Successful SDKResult data field : object (The transaction detail object returned by the Radix Gateway API)


Types and Classes

Various types and classes to make working with the SDK easier.

ApiNetwork (Type)

Type that specifies valid apiNetwork input values for the init function. Valid Values: | Value | Description | | "mainnet" | Connect to a public Alphadex Radix mainnet api server | | "stokenet" | Connect to a public Alphadex Radix stokenet api server | | "localhost-mainnet" | Connect to a locally hosted AlphaDEX Radix mainnet api server | | "localhost-stokenet" | Connect to a locally hosted AlphaDEX Radix stokenet api server |

Candle (Class/Type)

Object with information for a single candle in a candlestick graph. Candles are related to a pair, so references to token1 and token2 refer to the relevant tokens in the pair (see PairInfo).

Object Fields:

Field Description Type
startTime The start time of the candle. The time is presented in milliseconds since UNIX epoch (1 Jan 1970, 00:00:00 UTC) string
noTrades The number of trades that were recorded during the period for this candle number
tradesQuantity The value of token1 traded during the period for this candle number
tradesValue The value of token2 traded during the period for this candle number
priceHigh The highest price traded during the period for this candle number
priceLow The lowest price traded during the period for this candle number
priceOpen The last price traded before the start of the period for this candle number
priceClose The last price traded before the end of the period for this candle number

CandlePeriods (Array)

Array with all valid candle periods as strings. All times are based on UTC timezone. Useful if you need to provide a user with choices to select a candle period. Used in CurrentCandlePeriod.

Valid candle periods

Period Description
"5m" Period starting every 5 minutes. E.g. 13:00, 13:05 etc.
"15m" Period starting every 15 minutes. E.g. 13:00, 13:15 etc.
"30m" Period starting every 30 minutes. E.g. 13:00, 13:30 etc.
"1h" Period starting every 1 hour on the hour. E.g. 13:00, 14:00 etc.
"4h" Period starting every 4 hours on the hour. E.g. 12:00, 16:00 etc.
"6h" Period starting every 6 hour on the hour. E.g. 12:00, 18:00 etc.
"12h" Period starting every 12 hour on the hour. E.g. 00:00, 12:00 etc.
"1D" Period starting every day at the start of the day. E.g. 1 Jan 2023 00:00, 2 Jan 2023 00:00 etc.
"1W" Period starting every week at the start of the week (Monday). E.g. Monday 27 March 00:00, Monday 3 May 00:00 etc.
"1M" Period starting every month at the start of the month. E.g. 1 Jan 00:00, 1 Feb 00:00 etc.

ClientStatus (Type)

Shows the status of the connection with the AlphaDEX exchange. Can be one of 3 values:

  • "LOADING" - connection is being established and data is being received from exchange
  • "READY" - connection is ready and data is live
  • "OFFLINE" - connection is not working and data is not updating

MarketData (Class/Type)

Object with latest 24h market information for a pair.

Field Description Type
lastOrderId The id (unique identifier) of the last order that submitted for the pair. number
lastPrice The price of the latest trade for the pair. number
open24h The last price traded before the start of the current 24h period. number
change24h The change in price during the current 24h period expressed in decimals. This value is calculated as lastPrice / open24h - 1 number
high24h The highest price traded during the current 24h period. number
low24h The lowest price traded during the current 24h period. number
trades24h The number of trades during the current 24h period. number
quantity24h The total value of token1 traded during the current 24h period. number
value24h The total value of token2 traded during the current 24h period. number

Orderbook (Class/Type)

Object with information for an orderbook.

Field Description Type
buys List of buy order summaries per price Array of OrderbookLine
sells List of sell order summaries per price Array of OrderbookLine

OrderbookLine (Class/Type)

Object with information related to a specific price in an orderbook. OrderbookLine is related to a pair, so references to token1 and token2 refer to the relevant tokens in the pair (see pairInfo).

Field Description Type
price The price that this information is for. number
quantityRemaining The amount of token1 that remains available at this price. number
valueRemaining The amount of token2 that remains available at this price. number
noOrders The number of orders remaining at this price. number
orders A list of the actual orders remaining at this price Array of OrderInfo
total (optional) This field is not calculated in the SDK and will always be set to 0. It is included to be used when displaying the cumulative total quantity/value available in an orderbook across prices. This field will need to be populated and calculated by the user if required. number
change Shows whether this orderbook line was changed. It can be used to animate any changes in orderbook lines. boolean

OrderInfo (Class/Type)

Object with basic information for an order. OrderInfo is related to a pair, so references to token1 and token2 refer to the relevant tokens in the pair (see pairInfo).

Field Description Type
id Id (unique identifier) of the order. number
quantityRemaining Amount of token1 that remains available for the order. number
valueRemaining Amount of token2 that remains available for the order. number

OrderReceipt

Object with detailed information about an order.

Field Description Type
pairAddress The on-ledger component address of the AlphaDEX pair for this order. string
id The id (unique identifier) of the order. number
orderType The type of order. OrderType
side The side for the order. OrderSide
token The specified token for the order. TokenInfo
amount The specified amount of the order. number
price The specified price of the order. number
status The status of the order OrderStatus
completedPerc How much of the order has been completed, specified in decimals number
trades The trades for this order Array of Trade
unclaimedToken The token that the order owner will receive or can claim TokenInfo
unclaimedTokenAmount The amount of tokens that the order owner can still claim. number
timeSubmitted The time that the order was submitted, specified in millisends since the UNIX epoch. string
timeCompleted The time that the order was either completed or cancelled, specified in millisends since the UNIX epoch. string

OrderSide (Enum Type)

Enum type used to specify the side (buy or sell) of an order. E.g. to indicate a "Buy" order, you must specify either OrderSide.BUY or "BUY".

Enum String
BUY "BUY"
SELL "SELL"

OrderSideString (Type)

Utility type for when user must input OrderSide - restricts to only strings with valid values.

OrderStatus (Enum Type)

Enum type used to specify the status of an order.

Enum String
PENDING "PENDING"
COMPLETED "COMPLETED"
CANCELLED "CANCELLED"

OrderStatusString (Type)

Utility type for when user must input OrderStatus - restricts to only strings with valid values.

OrderType (Enum Type)

Enum type used to specify the type of an order. E.g. to indicate a "Limit" order, you must specify either OrderType.LIMIT or "LIMIT".

Enum String
LIMIT "LIMIT"
POSTONLY "POSTONLY"
MARKET "MARKET"

OrderTypeString (Type)

Utility type for when user must input OrderType - restricts to only strings with valid values.

PairInfo (Class/Type)

Object with information for a pair. Object Fields:

Field Description Type
address The on-ledger address of the pair component for the pair string
name Name for the pair. Will usually be a combination of the symbols of the tokens in the pair. e.g. ADEX/XRD string
token1 Basic information about the first token in this pair. TokenInfo
token2 Basic information about the second token in this pair. TokenInfo
dappDefAddress The on-ledger address of the dApp definition account for the pair string
orderReceiptAddress The on-ledger resource address of the order receipt NFT for the pair string
exchangeFee The exchange fee that applies for the pair number
liquidityFee The liquidity fee that applies for the pair number
token1Divisibility The maximum number of decimal digits allowed on ledger for token1. number
token1Divisibility The maximum number of decimal digits allowed on ledger for token2. number
token1MaxDecimals The maximum number of decimal digits allowed for any user input amount of token1. number
token2MaxDecimals The maximum number of decimal digits allowed for any user input amount of token2. number
priceMaxDecimals The maximum number of decimal digits allowed in the price of the pair. number
epochsPerPeriod The number of epochs between checking if the pair liquidity fee should be adjusted. number
lastEpochPeriod The last epoch that the liquidity fee of the pair was checked for adjustment. number
active Indicates whether the pair is still active. Pairs that are not active cannot accept new orders. boolean
lastPrice The price of the latest trade for the pair. number
open24h The last price traded before the start of the current 24h period. number
change24h The change in price during the current 24h period expressed in decimals. This value is calculated as lastPrice / open24h - 1 number
high24h The highest price traded during the current 24h period. number
low24h The lowest price traded during the current 24h period. number
trades24h The number of trades during the current 24h period. number
quantity24h The total value of token1 traded during the current 24h period. number
value24h The total value of token2 traded during the current 24h period. number

PlatformBadge (Class/Type)

Object with information for a platform badge. Object Fields:

Field Description Type
id The unique id of the platform badge number
name The user assigned name of the platform badge string
fee The fee that applies to this platform badge, specified in decimals. number
unclaimed_fees A map of the unclaimed fees for different pairs. The map is indexed by the pair id. For every pair there are 2 string values that represent the amount of token1 and token1 accumulated in fees for that pair. Map<number, [string, string]>

SDKResult (Class/Type)

Object that is returned from asynchronous (async) AlphaDEX SDK functions. It indicates whether the function completed successfully and might contain data that was returned from the function. Object Fields:

Field Description Type
status The status of the result returned from the function. Valid values = "SUCCESS", "ERROR". string
message (optional) Message related to the result returned from the function. string
data (optional) Data related to the result returned from the function any

Quote (Class/Type)

Object containing information about the estimated outcome of an AlphaDEX order. Object Fields:

Field Description Type
pairAddress The on-ledger address of the pair that this quote is for string
requiredAmount The estimated amount of tokens required to be sent for the transaction number
orderAmount The amount of tokens that need to be specified in the order transaction (for buy transactions this amount allows for fees) number
orderbookAmount The estimated amount of tokens that will be added to the orderbook number
fromToken Information about the token that will be sent in for the transaction TokenInfo
fromAmount The estimated amount of sent in tokens that will be matched in the transaction number
toToken Information about the token that will be received in the transaction TokenInfo
toAmount The estimated amount of tokens that will received for the transaction number
bestPrice The estimated best price that will be used in the transaction number
worstPrice The estimated worst price that will be used in the transaction number
avgPrice The estimated average price that will be used in the transaction number
slippage The estimated percentage price slippage that will happen in the transaction (expressed in decimals i.e. 0.1% = 0.001) number
exchangeFees The estimated exchange fee cost for the transaction (expressed in terms of the toToken) number
platformFees The estimated platform fee cost for the transaction (expressed in terms of the toToken) number
liquidityFees The estimated liquidity fee cost for the transaction (expressed in terms of the toToken) number
totalFees The estimated total fee cost (exchange + platform + liquidity) for the transaction (expressed in terms of the toToken) number
expectedResult Indicates whether the quote will result in a successfully committed transaction. "SUCCESS" or "FAILURE"
resultCode Standardised code for different quote outcomes. This code can be used to craft a custom message for each outcome rather than use the message provided in the message field. number
resultMessage Standardised message for each result code. See QuoteResultMessages below. string
resultMessageLong Longer, more descriptive result message. string

QuoteResultMessages

Standardised result messages for each quote resultCode.

Code Desciption
Failure Codes (0 - 99)
0 Default - result code has not been set - should not return this value ever
1 Incorrect token specified - Could not find a specified token in the pair
2 No buy/sell orders available in the pair.
3 No order could be matched with specified price
4 No order could be matched with specified slippage
5 Not enough total liquidity in orderbook to fulfill market order
6 Not enough liquidity within specified price/slippage limit to fulfill market order
Success Codes (100 - 199)
100 Order can be fulfilled completely
101 No match for price in limit order, order will be added to orderbook
102 MARKETPARTIAL order can be partially fulfilled and rest will be returned to user
103 LIMIT order can be partially fulfilled and rest will be added to orderbook

TokenInfo (Class/Type)

Object with basic information for a token as retrieved from the token definition on-ledger.

Field Description Type
address The on-ledger resource address of the token. string
symbol The symbol of the token. string
name The name of the token. string
iconUrl The url of the token icon. string

Trade (Class/Type)

Object with information about a trade.

Field Description Type
id Id (unique identifier) of the trade. number
token1Receiver Id (unique identifier) of the order (OrderReceipt) that received Token1 in the trade. number
token2Receiver Id (unique identifier) of the order (OrderReceipt) that received Token2 in the trade. number
token1Amount Amount of token1 traded. number
token1Amount Amount of token2 traded. number
timeStamp Time of the trade (specified in milliseconds since UNIX epoch). string

Readme

Keywords

none

Package Sidebar

Install

npm i alphadex-sdk-js

Weekly Downloads

27

Version

0.12.15

License

ISC

Unpacked Size

301 kB

Total Files

52

Last publish

Collaborators

  • fliebenberg